from django.test import TestCase
from django.test.client import Client

"""
Testira stranu profila
"""
class ProfileTestCase(TestCase):
    
    def setUp(self):
        pass

    def runTest(self):
        self.runViewProfile()
        self.runUpdateUserTest()
    
    def runViewProfile(self):
        c = Client()
        c.login(username='kokan', password='123')
        
        response = c.get("/mdcs/profile/")
        self.failIf(response == None)
        self.failIf(response.context == None)
        self.failUnlessEqual(len(response.context), 2)
        self.failIf(response.context[0]["form"] == None)
        
        form = response.context[0]["form"]
        self.assertTrue(form.instance.chess_recommended)
        self.assertTrue(form.instance.tf_recommended)
        self.assertEqual(form.instance.user.email, "branko@microsoft.com")

    def runUpdateUserTest(self):
        c = Client()
        c.login(username='kokan', password='123')
        
        response = c.post("/mdcs/profile/",
            {'image': '', 'chess_recommended': 'on', 'send_mail': 'on', 'email': 'branko@microsoft.com'})
        self.failIf(response == None)
        self.failUnlessEqual(response.status_code, 302)
        
        response = c.get("/mdcs/profile/")
        self.failIf(response == None)
        self.failIf(response.context == None)
        self.failUnlessEqual(len(response.context), 2)
        self.failIf(response.context[0]["form"] == None)
        self.assertEqual(len(response.context[0]["messages"]), 1)

        form = response.context[0]["form"]
        self.assertTrue(form.instance.chess_recommended)
        self.assertFalse(form.instance.tf_recommended)
        self.assertEqual(form.instance.user.email, "branko@microsoft.com")